package com.DJ.httpPost;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.util.StringUtils;

public class doGet {
    public static void main(String[] args) throws Exception {
        //创建HttpClient
        CloseableHttpClient httpClient = HttpClients.createDefault();
        String url = "http://localhost:8080/user/getOne/";
        String getUrl = url + "1";
        //创建Get请求
        HttpGet httpGet = new HttpGet(getUrl);

        //
        CloseableHttpResponse httpResponse = null;
        try {
            httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();

            String text = EntityUtils.toString(httpEntity);

            System.out.print("Content Text :: ");
            System.out.println(text);

        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw e;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            try {
                if (httpResponse != null)
                    httpResponse.close();
                httpClient.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
